package util

import (
    "golang.org/x/crypto/bcrypt"
)

// 加密密码
func HashAndSalt(pwd []byte) string {
    hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
    if err != nil {

    }
    return string(hash)
}

// 验证密码
func ComparePasswords(hashedPwd string, password []byte) bool {
    byteHash := []byte(hashedPwd)
    err := bcrypt.CompareHashAndPassword(byteHash, password)
    if err != nil {
        return false
    }
    return true
}
